package cn.itsub.sodo.action.base;

import cn.itsub.sodo.Node;
import cn.itsub.sodo.action.interval.IntervalAction;

/** 
 * 永久重复一个动作
 */
public class RepeatForever extends Action {
    protected IntervalAction other;

    public static RepeatForever create(IntervalAction action) {
        return new RepeatForever(action);
    }

    protected RepeatForever(IntervalAction action) {
        other = action;
    }

    @Override
    public Action copy() {
        return new RepeatForever(other.copy());
    }

    @Override
    public void start(Node aTarget) {
        super.start(aTarget);
        other.start(target);
    }

    @Override
    public void step(float dt) {
        other.step(dt);
        if (other.isDone()) {
            float diff = dt + other.getDuration() - other.getElapsed();
        	other.start(target);
        	other.step(diff);
        }
    }

    @Override
    public boolean isDone() {
        return false;
    }

	@Override
	public void update(float time) {
		// TODO Auto-generated method stub
		
	}
}
